package com.aaa.controller.sas;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.sas.TestPlanSas;
import com.aaa.service.sas.TestPlanSasService;
import com.github.pagehelper.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 测试计划fpa(TestPlanSas)表控制层
 *
 * @author makejava
 * @since 2022-08-31 09:27:23
 */
@RestController
@RequestMapping("testPlanSas")
public class TestPlanSasController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TestPlanSasService testPlanSasService;

    /**
     * 分页查询
     *
     * @param pageSortEntity
     * @param testPlanSas
     * @return
     */
    @RequestMapping("questionQueryPlan.do")
    public Result questionQueryPlan(PageSortEntity pageSortEntity, TestPlanSas testPlanSas) {
        List<TestPlanSas> testPlanSas1 = testPlanSasService.queryAllSasPlan(pageSortEntity, testPlanSas);
        Page<TestPlanSas> page = (Page) testPlanSas1;
        return success(page.getResult(), page.getTotal());
    }

    @RequestMapping("QuestionSaSPlanDel.do")
    public Result questionDelPlan(Integer id) {
        boolean b = testPlanSasService.deleteById(id);
        if (b) {
            return success();
        } else {
            return fail();
        }
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TestPlanSas> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.testPlanSasService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param testPlanSas 实体
     * @return 新增结果
     */
    @PostMapping("savePlan.do")
    public Result add(TestPlanSas testPlanSas) {
        TestPlanSas insert = testPlanSasService.insert(testPlanSas);
        return success(insert);
    }




    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.testPlanSasService.deleteById(id));
    }

    @RequestMapping(value = "testDel.do")
    public Result delete(int[] id) {
        int delete = testPlanSasService.delete(id);
        if (delete > 0) {
            return success();
        } else {
            return fail();
        }
    }

    @GetMapping("repetitionName.do")
    public Result repetitionName(TestPlanSas testPlanSas) {
        boolean b = this.testPlanSasService.repetitionName(testPlanSas);
        if (b) {
            return success("计划名称可用");
        }
        return fail("计划名称重复，不可用");
    }

    @RequestMapping(value = "testUpdate.do")
    public Result update(TestPlanSas testPlanSas) {
        boolean update = testPlanSasService.update(testPlanSas);
        if (update) {
            return success();
        } else {
            return fail();
        }
    }

}

